<?php
namespace Communal\Model;
use Think\Model;
class MediaReportModel extends Model {
	protected $connection = 'DB_BASE_DSN';
	protected $tableName = 'qyx_media_report'; 
	
	public function getReportList($data){
		$map = array();
		$total = $this->where($map)->count();
		$fields = array('id','title','abstract','source','author','image','custid','reporttime');
		
		if(empty($data['sortField']))$data['sortField'] = "id";
		if(empty($data['sortOrder']))$data['sortOrder'] = "desc";
		
		if(empty($data['pageSize']) && empty($data['pageIndex']))
			$result = $this->field($fields)->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->select();
		else 
			$result = $this->field($fields)->where($map)->order("{$data['sortField']} {$data['sortOrder']}")->limit($data['pageIndex']*$data['pageSize'] , $data['pageSize'])->select();
		
		return array('total'=>$total , 'data'=>$result);
	}
	
	
	public function getReportById($id){
		$map['id'] = $id;
		$fields = array('id','title','abstract','source','author','image','content','custid','reporttime');
		$result = $this->field($fields)->where($map)->find();
		return $result;
	}
	
	
	public function addReport($data){
		$result = $this->add($data);
		return $result;
	}
	
	public function updateReport($data){
		$map['id'] = $data['id'];
		$data['updatetime'] = date("Y-m-d H:i:s");
		$result = $this->where($map)->save($data);
		return $result;
	}
	
	public function deleteReport($data){
		$map['id'] = $data['id'];
		$result = $this->where($map)->delete();
		return $result;
	}
	
}


